package com.atguigu.e_reflect.field;

import java.lang.reflect.Field;

public class Demo {
    public static void main(String[] args) throws NoSuchFieldException {
        //反射第一步 : 获取类的字节码对象
        Student stu = new Student();
        Class<? extends Student> clazz = stu.getClass();

        //获取类中所有的成员变量对象
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            System.out.println("field = " + field);
        }
        System.out.println("-----------------------");
        //获取指定的成员变量对象
        Field name = clazz.getDeclaredField("name");
        System.out.println("name = " + name);

        Field age = clazz.getDeclaredField("age");
        System.out.println("age = " + age);

        Field gender = clazz.getDeclaredField("gender");
        System.out.println("gender = " + gender);

        Field salary = clazz.getDeclaredField("salary");
        System.out.println("salary = " + salary);
    }
}
